#include "solve.h"
#include "matrix.h"

Matrix LS_C(Matrix a, Matrix b)     //正则化方法求解最小二乘问题
{
    Matrix c = trans(a);
    Matrix d = c * a;
    Matrix e = c * b;
    cholesky(d, e.datap);
}

void LS_QR(Matrix a, Matrix b)      //正交化方法求解最小二乘问题
{
    Matrix c = QR(a);
    Matrix d = QR_Q(a);
    Matrix h = d.cut(1, d.row, 1, a.col);
    Matrix e = trans(h)*b;
    double *x = (double *)malloc(sizeof(double)*a.col);
    x = up(c, e.datap);
    for (int k = 0; k < a.col; k++)
    {
        std::cout << x[k] << std::endl;
    }
}

/*int main()
{
    double p[6] = {1, 2, 3, 4, 5, 6};
    Matrix a(3, 2, p);
    double q[3] = {1, 1, 1};
    Matrix b(3, 1, q);
    LS_QR(a, b);
    return 0;
}*/